package Common.Entities;

import java.util.LinkedList;
import java.io.Serializable;

/**
 * This class holds the Product's and product-picture's entities properties and methods
 * @author ori ziv
 *
 */
public class Product implements Serializable{
	private static final long serialVersionUID = 8727177712307401481L;
	private long productID;
	private String productName;
	private String productDescription;
	private float productBasePrice;
	private STATUS productStatus;
	private LinkedList <Type>productCategoriesAndTypes;
	private ProductPicture picture;
	
	/**
	 * @param productName
	 * @param productDescription
	 * @param productBasePrice
	 * @param productStatus
	 */
	public Product(String productName, String productDescription,
			float productBasePrice, STATUS productStatus) {
		super();
		this.productName = productName;
		this.productDescription = productDescription;
		this.productBasePrice = productBasePrice;
		this.productStatus = productStatus;
		this.productCategoriesAndTypes = new LinkedList<Type>();
		picture = null;
	}
	
	/**
	 * @param productID
	 * @param productName
	 * @param productDescription
	 * @param productBasePrice
	 * @param productStatus
	 */
	public Product(long productID, String productName,
			String productDescription, float productBasePrice,
			STATUS productStatus) {
		this(productName, productDescription, productBasePrice, productStatus);
		this.productID = productID;
	}
	/**
	 * @return the productID
	 */
	public long getProductID() {	return productID; }
	/**
	 * @param productID the productID to set
	 */
	public void setProductID(int productID) { this.productID = productID; }
	/**
	 * @return the productName
	 */
	public String getProductName() { return productName; }
	/**
	 * @param productName the productName to set
	 */
	public void setProductName(String productName) { this.productName = productName; }
	/**
	 * @return the productDescription
	 */
	public String getProductDescription() { return productDescription; }
	/**
	 * @param productDescription the productDescription to set
	 */
	public void setProductDescription(String productDescription) { this.productDescription = productDescription; }
	/**
	 * @return the productBasePrice
	 */
	public float getProductBasePrice() { return productBasePrice; }
	/**
	 * @param productBasePrice the productBasePrice to set
	 */
	public void setProductBasePrice(float productBasePrice) { this.productBasePrice = productBasePrice; }
	/**
	 * @return the productStatus
	 */
	public STATUS getProductStatus() { return productStatus; }
	/**
	 * @param productStatus the productStatus to set
	 */
	public void setProductStatus(STATUS productStatus) { this.productStatus = productStatus; }
	
	/**
	 * Check if this product is associated with a specific product type
	 * @param type
	 * @return - true if product is associated otherwise return false
	 */
	public boolean isLinkedToType (Type type) {
		for (int i = 0 ; i < this.productCategoriesAndTypes.size() ; i ++)
			if (this.productCategoriesAndTypes.get(i).getItmID().equals(type.getItmID()))
				return true;
		return false;
	}
	
	/**
	 * Add specific type to product's type association list.
	 * This DOES NOT register the relation in the DB
	 * @param type
	 * @return - true in case of success otherwise return false
	 */
	public boolean addTypeToProduct (Type type) {
		if (!isLinkedToType(type)) {
			this.productCategoriesAndTypes.add(type);
			return true;
		}
		return false;
	}
	
	/**
	 * Remove specific type from product's type association list.
	 * This DOES NOT unregister the relation in the DB
	 * @param type
	 * @return - true in case of success otherwise return false
	 */
	public boolean removeTypeFromProduct (Type type) {
		for (int i = 0 ; i < this.productCategoriesAndTypes.size() ; i ++)
			if (this.productCategoriesAndTypes.get(i).getItmID().equals(type.getItmID())) {
				this.productCategoriesAndTypes.remove(i);
				return true;
			}
		return false;
	}
	
	/**
	 * @return the picture
	 */
	public ProductPicture getPicture() {
		return picture;
	}
	/**
	 * @param picture the picture to set
	 */
	public void setPicture(ProductPicture picture) {
		this.picture = picture;
	}
	/**
	 * @return the productCategoriesAndTypes
	 */
	public LinkedList<Type> getProductCategoriesAndTypes() {
		return productCategoriesAndTypes;
	}
}
